﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using System.Data.SqlClient;
using QLTV.DAL;
using QLTV.Public;

namespace QLTV.DAL
{
    public class PhieuSachDAL
    {
        ConnectionData connect;
        public DataTable DauSach_LoadSach()
        {
            try
            {
                connect = new ConnectionData();
                return connect.GetData("DAUSACH_LOAD");
            }
            catch (SqlException ex)
            {
                throw ex;
            }
        }
        public DataTable LoadSach_ThemSach(SachDTO p)
        {
            try
            {
                connect = new ConnectionData();
                int Nparamater = 1;
                string[] name = new string[Nparamater];
                object[] value = new object[Nparamater];
                name[0] = "@MaSach";
                value[0] = p.MaSach;
                return connect.GetData("PHIEUSACH_THEMSACH", name, value, Nparamater);
            }
            catch (SqlException ex)
            {
                throw ex;
            }
        }

        public DataTable LoadSach_TimSach(DauSachDTO p)
        {
            try
            {
                connect = new ConnectionData();
                int Nparamater = 1;
                string[] name = new string[Nparamater];
                object[] value = new object[Nparamater];
                name[0] = "@MaDS";
                value[0] = p.MaDS;
                return connect.GetData("PHIEUSACH_TIMSACH", name, value, Nparamater);
            }
            catch (SqlException ex)
            {
                throw ex;
            }
        }
        public DataTable PhieuMuonSach_ThemSach_MaSach(SachDTO p)
        {
            try
            {
                connect = new ConnectionData();
                int Nparamater = 1;
                string[] name = new string[Nparamater];
                object[] value = new object[Nparamater];
                name[0] = "@MaSach";
                value[0] = p.MaSach;
                return connect.GetData("PHIEUSACH_PhieuMuonSach_ThemSach_MaSach", name, value, Nparamater);
            }
            catch (SqlException ex)
            {
                throw ex;
            }
        }

        public DataTable PhieuMuonSach_TimSach_MaDS(DauSachDTO p)
        {
            try
            {
                connect = new ConnectionData();
                int Nparamater = 1;
                string[] name = new string[Nparamater];
                object[] value = new object[Nparamater];
                name[0] = "@MaDS";
                value[0] = p.MaDS;
                return connect.GetData("PHIEUSACH_PhieuMuonSach_TimSach_MaDS", name, value, Nparamater);
            }
            catch (SqlException ex)
            {
                throw ex;
            }
        }

        public DataTable PhieuMuonSach_TimSach_TenDS(DauSachDTO p)
        {
            try
            {
                connect = new ConnectionData();
                int Nparamater = 1;
                string[] name = new string[Nparamater];
                object[] value = new object[Nparamater];
                name[0] = "@TenDS";
                value[0] = p.TenDS;
                return connect.GetData("PHIEUSACH_PhieuMuonSach_TimSach_TenDS", name, value, Nparamater);
            }
            catch (SqlException ex)
            {
                throw ex;
            }
        }

        public DataTable PhieuTraSach_TimDocGia_MaDG(DocGiaDTO p)
        {
            try
            {
                connect = new ConnectionData();
                int Nparamater = 1;
                string[] name = new string[Nparamater];
                object[] value = new object[Nparamater];
                name[0] = "@MaDG";
                value[0] = p.MaDG;
                return connect.GetData("PHIEUSACH_PhieuTraSach_TimDocGia_MaDG", name, value, Nparamater);
            }
            catch (SqlException ex)
            {
                throw ex;
            }
        }

        public int ChoMuonSach(PhieuSachDTO p)
        {
            try
            {
                connect = new ConnectionData();
                int Nparamater = 1;
                string[] name = new string[Nparamater];
                object[] value = new object[Nparamater];
                name[0] = "@MaDG";
                value[0] = p.MaDG;
                return connect.UpdateData("PHIEUSACH_Insert", name, value, Nparamater);
            }
            catch (SqlException ex)
            {
                throw ex;
            }
        }

        public DataTable PhieuTraSach_TimPhieuSach_MaDG(PhieuSachDTO p)
        {
            try
            {
                connect = new ConnectionData();
                int Nparamater = 1;
                string[] name = new string[Nparamater];
                object[] value = new object[Nparamater];
                name[0] = "@MaDG";
                value[0] = p.MaDG;
                return connect.GetData("PHIEUSACH_PhieuTraSach_TimPhieuSach_MaDG", name, value, Nparamater);
            }
            catch (SqlException ex)
            {
                throw ex;
            }
        }

        public DataTable PhieuMuonSach_KiemTraDaTra_MaDG(PhieuSachDTO p)
        {
            try
            {
                connect = new ConnectionData();
                int Nparamater = 1;
                string[] name = new string[Nparamater];
                object[] value = new object[Nparamater];
                name[0] = "@MaDG";
                value[0] = p.MaDG;
                return connect.GetData("PHIEUSACH_PhieuMuonSach_KiemTraDaTra_MaDG", name, value, Nparamater);
            }
            catch (SqlException ex)
            {
                throw ex;
            }
        }

        public DataTable PhieuTraSach_HienSachTra_MaDG(PhieuSachDTO p)
        {
            try
            {
                connect = new ConnectionData();
                int Nparamater = 1;
                string[] name = new string[Nparamater];
                object[] value = new object[Nparamater];
                name[0] = "@MaDG";
                value[0] = p.MaDG;
                return connect.GetData("PHIEUSACH_PhieuTraSach_HienSachTra_MaDG", name, value, Nparamater);
            }
            catch (SqlException ex)
            {
                throw ex;
            }
        }

        public int NhanTraSach(PhieuSachDTO p)
        {
            try
            {
                connect = new ConnectionData();
                int Nparamater = 5;
                string[] name = new string[Nparamater];
                object[] value = new object[Nparamater];
                name[0] = "@MaPhieu";
                value[0] = p.MaPhieu;
                name[1] = "@NgayTra";
                value[1] = p.NgayTra;
                name[2] = "@SoNgayMuon";
                value[2] = p.SoNgayMuon;
                name[3] = "@TienPhatKyNay";
                value[3] = p.TienPhatKyNay;
                name[4] = "@SoTienThu";
                value[4] = p.SoTienThu;
                return connect.UpdateData("PHIEUSACH_UPDATE", name, value, Nparamater);
            }
            catch (SqlException ex)
            {
                throw ex;
            }
        }
        public DataTable QuanLyMuonTra_LoadPhieuSachChuaTra()
        {
            try
            {
                connect = new ConnectionData();

                return connect.GetData("PHIEUSACH_QuanLyMuonTra_LoadPhieuSachChuaTra");
            }
            catch (SqlException ex)
            {
                throw ex;
            }
        }

        public DataTable QuanLyMuonTra_LoadSachChuaTra()
        {
            try
            {
                connect = new ConnectionData();

                return connect.GetData("PHIEUSACH_QuanLyMuonTra_LoadSachChuaTra");
            }
            catch (SqlException ex)
            {
                throw ex;
            }
        }

        public DataTable LoadPhieuSachQuaHan()
        {
            try
            {
                connect = new ConnectionData();

                return connect.GetData("PHIEUSACH_QuanLyMuonTra_LoadPhieuSachQuaHan");
            }
            catch (SqlException ex)
            {
                throw ex;
            }
        }

        public DataTable QuanLyMuonTra_LoadSachDaTra()
        {
            try
            {
                connect = new ConnectionData();

                return connect.GetData("PHIEUSACH_QuanLyMuonTra_LoadSachDaTra");
            }
            catch (SqlException ex)
            {
                throw ex;
            }
        }

        public DataTable QuanLyMuonTra_LoadPhieuSachDaTra()
        {
            try
            {
                connect = new ConnectionData();

                return connect.GetData("PHIEUSACH_QuanLyMuonTra_LoadPhieuSachDaTra");
            }
            catch (SqlException ex)
            {
                throw ex;
            }
        }
    }
}
